package com.ruoyi.camp.api;

import com.ruoyi.camp.domain.CScenicSpots;
import com.ruoyi.camp.domain.WxCScenicSpots;
import com.ruoyi.camp.service.ICScenicSpotsService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 营地景点Controller
 * 
 * @author ruoyi
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/wechat/spots")
public class WxCScenicSpotsController extends BaseController
{
    @Autowired
    private ICScenicSpotsService cScenicSpotsService;
    @GetMapping("/getInfoByCampId/{campid}")
    public AjaxResult getInfoByCampId(@PathVariable("campid") String campId) {
        if (campId == null) {
            return error("营地Id不能为空");
        }
        List<CScenicSpots> list = cScenicSpotsService.getInfoByCampId(campId);
        return success(list);
    }

    @GetMapping("/getInfoByScenicId/{scenicid}")
    public AjaxResult getInfoByScenicId(@PathVariable("scenicid") String scenicId) {
        if (scenicId == null) {
            return error("周边景点Id不能为空");
        }
        CScenicSpots ScenicSpots = cScenicSpotsService.getInfo(scenicId);
        return success(ScenicSpots);
    }
    /**
     * 新增营地景点
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CScenicSpots ScenicSpots){
        if (ScenicSpots == null) {
            return error("数据不能为空");
        }
        if (ScenicSpots.getCampid() == null) {
            return error("营地Id不能为空");
        }
        if (ScenicSpots.getScenicname() == null) {
            return error("景点名称不能为空");
        }
        if (ScenicSpots.getLatitude() == null || ScenicSpots.getLongitude() == null) {
            return error("经纬度不能为空");
        }
        return toAjax(cScenicSpotsService.insertCScenicSpots(ScenicSpots));
    }
    /**
     * 修改营地景点
     */
    @PreAuthorize("@ss.hasPermi('camp:spots:edit')")
    @Log(title = "营地景点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CScenicSpots cScenicSpots)
    {
        return toAjax(cScenicSpotsService.updateCScenicSpots(cScenicSpots));
    }
    @PutMapping("/update")
    public AjaxResult update(@RequestBody CScenicSpots ScenicSpots) {
        if (ScenicSpots == null) {
            return error("数据不能为空");
        }
        if (ScenicSpots.getScenicid() == null) {
            return error("营地景点Id不能为空");
        }
        if (ScenicSpots.getCampid() == null) {
            return error("营地Id不能为空");
        }
        if (ScenicSpots.getScenicname() == null) {
            return error("景点名称不能为空");
        }
        if (ScenicSpots.getLatitude() == null || ScenicSpots.getLongitude() == null) {
            return error("经纬度不能为空");
        }
        return toAjax(cScenicSpotsService.updateCScenicSpots(ScenicSpots));
    }
    /**
     * 删除营地景点
     */
    @DeleteMapping("/delete/{scenicid}")
    public AjaxResult delete(@PathVariable("scenicid") String scenicId){
        if (scenicId == null) {
            return error("周边景点Id不能为空");
        }
        return toAjax(cScenicSpotsService.deleteCScenicSpotsByScenicid(scenicId));
    }
//    @PutMapping("/approve")
//    public AjaxResult approve(@RequestBody WxCScenicSpots ScenicSpots) {
//        return toAjax(cScenicSpotsService.approve(ScenicSpots.getScenicid(),ScenicSpots.getApprove(),ScenicSpots.getContent()));
//    }
}
